package logic

import (
	"context"
	"errors"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/dao"
	"homepage_srv/internal/svc"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodRecommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodRecommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodRecommentLogic {
	return &GoodRecommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品推荐
func (l *GoodRecommentLogic) GoodRecomment(in *homepage.GoodRecommentRequest) (*homepage.GoodRecommentResponse, error) {
	goodRecomment, err := dao.GoodRecomment(in)
	if err != nil {
		pkg.Error("热门商品展示失败: %s", zap.Error(err))
		return nil, errors.New("热门商品展示失败")
	}
	pkg.Info("热门商品展示成功")
	return &homepage.GoodRecommentResponse{
		List: goodRecomment,
	}, nil
}
